using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace DbService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    //[WebService(Namespace = "http://LAP0180/")]
    [WebService(Namespace = "http://localhost")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class DbService : System.Web.Services.WebService
    {

        [WebMethod]
        public bool ValidateLogin(string _username, string _password)
        {
            SqlConnection sqlConn = null;
            SqlDataReader sqlRdr = null;

            try
            {
               sqlConn = new SqlConnection(Global.GetConnectionString());
               sqlConn.Open();

               SqlCommand sqlcmdValidateLogin = new SqlCommand("sp_validateLogin", sqlConn);
               sqlcmdValidateLogin.CommandType = CommandType.StoredProcedure;

               sqlcmdValidateLogin.Parameters.Add( new SqlParameter("email", _username) );
               sqlcmdValidateLogin.Parameters.Add( new SqlParameter("password", _password) );

               sqlRdr = sqlcmdValidateLogin.ExecuteReader();
               sqlRdr.Read();

               if (1 == (int)sqlRdr["success"])
               {
                  return true;
               }
            }
            catch (SqlException ex)
            {
               ex.ToString();
            }
            finally
            {
               if (null != sqlRdr)
               {
                  sqlRdr.Close();
               }

               if (null != sqlConn)
               {
                  sqlConn.Close();
               }
            }

            return false;
        }
    }
}
